/*
 * Main.java
 *
 * Created on August 27, 2006, 5:45 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package flickit;

import java.io.IOException;
import java.util.*;
import com.aetrion.flickr.*;
import com.aetrion.flickr.photosets.*;
import org.xml.sax.SAXException;
import java.io.*;
import javax.swing.ImageIcon;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

/**
 *
 * @author afung
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main( String username, String filepath )
    {
        String apiKey = "b5da4c26c16e488fdfcf5ff66b6e9326";
        Flickr f = new Flickr(apiKey);
        PhotosetsInterface setiface = f.getPhotosetsInterface();
        Photosets photosets;
        
        
        FlickrJ flickrj = new FlickrJ (apiKey);
        String userid = flickrj.getUserId( username );
        flickrj.listPhotosByPhotosetId( "72157594249967847" );

        // check each picture in directory
        File picdir = new File( filepath );
        File[] files = picdir.listFiles();
        for ( int i=0; i < files.length; i++ ) {
            File curfile = files[i];
            if ( curfile.isFile() && curfile.getName().endsWith(".jpg") ) {
                BufferedImage bufimg;
                try {
                    bufimg = ImageIO.read(files[i]);
                    //System.out.println ( files[i].getName() );
                    //System.out.println ( bufimg.getHeight() );
                    //System.out.println( bufimg.getWidth() );
                    
                    if (! flickrj.isPhotoInSet( files[i].getName(), bufimg.getWidth(), bufimg.getHeight() ) ) {
                        System.out.println ( "Not in set: " + files[i].getName() );
                    }
                    
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
        
                
        // System.out.println( "InSet? " + flickrj.isPhotoInSet( "DSC_0355.jpg", 1901, 1411 ) );
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if ( args.length != 2 ) {
            System.err.println( "Invalid arguments" );
            System.out.println( "java -jar FlickIt <username> <path to file>" );
            System.exit( 1 );
        }
        new Main( args[0], args[1] );
    }
    
}
